﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Awesomium.Core;
using System.Threading;

namespace BrowserPL3
{
    /// <summary>
    /// Interaction logic for MainStructure.xaml
    /// </summary>
    public partial class TabStructure : Window
    {
        public TabStructure()
        {
            InitializeComponent();
           
        }

        /// <summary>
        /// back button clicked
        /// <remarks>
        /// it go back </remarks>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void back_click(object sender, RoutedEventArgs e)
        {
            try
            {
                //check if can go back
                if (WebBrowser1.CanGoBack())
                {
                    WebBrowser1.GoBack();
                }
            }
            catch { };
        }

        /// <summary>
        /// forward buton clicked
        /// <remarks>
        /// it go forward</remarks>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void next_click(object sender, RoutedEventArgs e)
        {
            try
            {
                //check if can go forward
                if (WebBrowser1.CanGoForward())
                {
                    WebBrowser1.GoForward();
                }
            }
            catch { };
        }

        /// <summary>
        /// refreash button click
        /// <remarks>
        /// it refreashed the content of the page</remarks>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refresh_click(object sender, RoutedEventArgs e)
        {
            try
            {
                WebBrowser1.Reload(true);
            }
            catch { };
        }


        /// <summary>
        /// this function fired when enter key clicked 
        /// <remarks>
        /// if the address bar have url it navigate to it 
        /// otherwise it search to the  enterd word in google</remarks>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Text_Key_Down(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                try
                {
                    if ((URL_Text.Text.Contains(".com") || (URL_Text.Text.Contains(".net"))))
                    {

                        WebBrowser1.Source = URL_Text.Text.ToUri();



                    }

                    else
                    {

                        WebBrowser1.Source = new Uri("https://www.google.com.eg/#q=" + URL_Text.Text);


                    }
                }
                catch { }

            }
        }


        /// <summary>
        /// 
        ///function for home button clicked that is when clicked goes  to home page
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void homePage(object sender, RoutedEventArgs e)
        {
            WebBrowser1.Source = new Uri(Properties.Settings.Default.Homepage);
        }

        //happens when the WebControl navigate to another Page
        private void updatePageName(object sender, UrlEventArgs e)
        {
            URL_Text.Text = WebBrowser1.Source.ToString();
        }

        private void updateTitle(object sender, TitleChangedEventArgs e)
        {
            PageName.Text = WebBrowser1.Title;
        }
        

    }
}
